package com.zzj.controller;

import com.github.pagehelper.PageInfo;
import com.zzj.ServiceImpl.BuyServiceImpl;
import com.zzj.bean.BuyBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
//@CrossOrigin
@RequestMapping("buy")
public class BuyController {
    @Autowired
    private BuyServiceImpl service;

    @GetMapping("findAll")
      public PageInfo<BuyBean> findAllBuy( int pageNum,
                                          int pageSize,Integer userId){

          PageInfo<BuyBean> info = service.selectAllBuy(pageNum,pageSize,userId);
          return info;
      }
      @PutMapping("updateOneBuy")
      public boolean updateOneBuy(BuyBean bean){
          boolean b = service.updateOneBuy(bean);
          return b;
      }
      @PostMapping("insertOne/{userId}")
      public boolean insertOneBuy( @RequestBody BuyBean bean,@PathVariable("userId") int userId){
          System.out.println(userId+"11111111111111111111111111111111");
          System.out.println(bean);
          boolean b = service.insertOneBuy(bean,userId);
          return b;
      }
      @PostMapping("updateOneState")
      public boolean updateBuyState(int bid){
          boolean b = service.updateBuyStateById(bid);
          return b;
      }
      @GetMapping("assert")
      public boolean allertOne(int bid,int userId){
          boolean b = service.allertDeptName(bid, userId);

          return b;
      }
      @GetMapping("deleteOneBuy")
      public boolean deleteOneBuy(int bid){
          boolean b = service.deleteOneBuyStateById(bid);
          return b;
      }
      @GetMapping("report")
      public boolean reportOneBuy(int bid){
          boolean b = service.updateBuyStateById(bid);
          return b;
      }
      @GetMapping("findAllBuyByDname")
      public PageInfo<BuyBean> findAllBuyByDname(int pageNum,int pageSize,String dname){
          PageInfo<BuyBean> info = service.selectAllBuy(dname, pageNum, pageSize);
          return info;
      }
    /**
     * 定义一个测试的用户Id,传输到前端
     */
    @GetMapping("sendOneUserId")
    public Integer sendOneUserId(){
        return 8;
    }
}
